# -*- coding: UTF-8 -*- #
"""
-------真正的勇士， 敢于直面惨淡的Warning、 敢于正视淋漓的Error-----
@author : 贾鹏博
@file : qiyeweixin_app.py
@time : 2022/6/11 17:29
"""
from appium import webdriver
from apptest.XueQiu_PO.base.base_page import BasePage


# app相关的操作 ： 雪球应用的 start 启动 ， 重启 restart , 停止 stop


class XueQiuApp(BasePage):

    def start(self):
        # 启动 雪球 app
        # 如果等于 None ，则直接启动 app。不等于 None ,则复用之前的 app(不用在重新启动耗资源)
        if self.driver == None:
            print('driver == None')
            desired_caps = {}
            desired_caps['platformName'] = "Android"
            desired_caps['platformVersion'] = '6.0'
            desired_caps['deviceName'] = 'emulator-5554'
            desired_caps['appPackage'] = 'com.xueqiu.android'
            desired_caps['appActivity'] = '.view.WelcomeActivityAlias'
            desired_caps['noReset'] = 'true'
            self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
            # 隐式等待
            self.driver.implicitly_wait(5)
        else:
            print('复用 driver')
            # 直接启动app
            self.driver.launch_app()
        return self

    def restart(self):
        pass

    def stop(self):
        self.driver.quit()

    def goto_main(self):
        from apptest.XueQiu_PO.page.main_page import Mainpage
        return Mainpage(self.driver)
